﻿using Abp.Dependency;
using Abp.Events.Bus;
using Abp.Threading;
using Abp.Threading.BackgroundWorkers;
using Abp.Threading.Timers;
using ARchGL.Platform.EventHandlers.Events;

namespace ARchGL.Platform.BackgroundWorker
{
    /// <summary>千变整体数据同步</summary>
    public class QianbianSyncWorker : PeriodicBackgroundWorkerBase, ISingletonDependency
    {
        public IEventBus EventBus { get; set; }

        public QianbianSyncWorker(AbpTimer timer) : base(timer)
        {
            EventBus = NullEventBus.Instance;
            Timer.Period = 60 * 60 * 1000; //60分钟一次
        }

        protected override void DoWork()
        {
            AsyncHelper.RunSync(() => EventBus.TriggerAsync(new QianbianSyncEvent(0)));
        }
    }

    /// <summary>千变考勤数据同步</summary>
    public class QianbianAttendancesSyncWorker : PeriodicBackgroundWorkerBase, ISingletonDependency
    {
        public IEventBus EventBus { get; set; }
        //private readonly int[] hourArray = new int[] { 6, 7, 8, 9, 17, 18, 19 };

        public QianbianAttendancesSyncWorker(AbpTimer timer) : base(timer)
        {
            EventBus = NullEventBus.Instance;
            Timer.Period = 5 * 60 * 1000; //5分钟一次
        }

        protected override void DoWork()
        {
            //if (!hourArray.Contains(DateTime.Now.Hour)) return;//上下班期间快速同步考勤

            AsyncHelper.RunSync(() => EventBus.TriggerAsync(new QianbianSyncEvent(QB_EnumEventArg.考勤)));
        }
    }
}
